


//
//
// function ii(obj) {
//     //解决C:\fakepath问题-----base64
//     var piclen = (obj.files[0].size / 1024).toFixed(0);
//     //判断图片大小
//     if (piclen > 333333) {
//         alert('你选择的文件大小超过25KB，请重新选择！');
//         return;
//     }
//     var oFReader = new FileReader();
//     var file = obj.files[0];
//     oFReader.readAsDataURL(file);
//     oFReader.onloadend = function (oFRevent) {
//         src = oFRevent.target.result;
//         console.info("--->>" + src)
//     };
//     //判断图片格式
//     var fileName = obj.value;
//     var suffixIndex = fileName.lastIndexOf(".");
//     var suffix = fileName.substring(suffixIndex + 1).toUpperCase();
//     if (suffix != "BMP" && suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF") {
//         alert("请上传图片（格式BMP、JPG、JPEG、PNG、GIF等）!");
//     }
// }

function changePic(item) {

    console.log($(item)[0].files[0]);
    var formdata=new FormData();

    let fakeurl = $(item).val();
    let url;
    console.log(fakeurl);
    formdata.append("pic",$(item)[0].files[0]);
    let  fileObj =$(item)[0].files[0]

    if (window.createObjcectURL != undefined) {
        url = window.createOjcectURL(fileObj);
    } else if (window.URL != undefined) {
        url = window.URL.createObjectURL(fileObj);
    } else if (window.webkitURL != undefined) {
        url = window.webkitURL.createObjectURL(fileObj);
    }



    console.log(url);


    $('#product-img').attr('src',url);

    // $.ajax({
    //     type:'POST',
    //     url:'/cl/uploadpic',
    //     data:formdata,
    //     contentType:false,
    //     processData:false,
    //     success:function (data) {
    //         alert("上传成功");
    //
    //     }
    // })
}


$(function () {







    //todo 之后请封装一下，看不下去了！！！
    $('.my-info').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#my-info').attr('class', 'list-content-active');
    })

    $('.history-orders').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#history-orders').attr('class', 'list-content-active');

    })

    $('.Shipping-Address').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#Shipping-Address').attr('class', 'list-content-active');
        $.ajax({
            type: 'GET',
            url: _common_util.getServerURL('admin/get_account'),
            success:function (res) {
                if (res.status === 0){
                    let name = res.data.username;
                    console.log(res);
                    $('.address-list').html('');
                    $.each(res.data.addressList,function (i,item) {
                        console.log(item);
                        str= '                          <div class="address-item" >\n' +
                            '                                        <div>\n' +
                            '                                            <span>'+name+'</span>\n' +
                            '                                            <span>'+res.data.phoneNumber+'</span>\n' +
                            '                                        </div>\n' +
                            '                                        <div>\n' +
                            '                                            <span class="saved-address">'+item+'</span>\n' +
                            '                                        </div>\n' +
                            '                                        <div>\n' +
                            '                                            <a class="btn-info" style="display: inline-block" >编辑</a>\n' +
                            '                                            <a class="btn-info" style="display: inline-block">删除</a>\n' +
                            '                                        </div>\n' +
                            '\n' +
                            '                                    </div>';

                        $('.address-list').append(str);
                    })
                }
            }
        })


    })

    $('.pay-info').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#pay-info').attr('class', 'list-content-active');
    })

    $('.my-product').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#my-product').attr('class', 'list-content-active');
    })

    $('.real-name').on('click', function () {
        $('#my-info-content').find('.list-content-active').attr('class', 'list-content');
        $('#my-info-content').find('#real-name').attr('class', 'list-content-active');
    })

    $('.user-exit').on('click', function () {
        user.userexit();
    })



    $('#save-address-btn').on('click',function () {
        _address.addNewAddress();
    })

    $('#identify').on('click',function(){
        let username = localStorage.getItem('username');
        let answer = localStorage.getItem('answer');
        let IDcard = $('#id-card').val();
        let realName = $('#userrealname').val();
        let realanswer = $('#realanswer').val();
        

        if(IDcard =='' || realName == '' || answer == ''){
            $('#username-error').css('display','inline-block').html('请将信息填写完整')
        }else {
                $.ajax({
                    type: 'POST',
                    url: _common_util.getServerURL('admin/authentication'),
                    data:{
                        'realName': realName,
                        "idCard": IDcard,
                        "answer": realanswer
                    },
                    success:function(res){
                        console.log(res)
                        if(res.status === 0){
                           window.wxc.xcConfirm('认证成功','success',{onOk:function () {
                                   location.reload();
                               }})

                        }else if(res.status == 11){
                            $('#answer-error').css('display','inline-block').html('问题回答错误')
                        }else if(res.status == 3){
                            alert("请先登录")
                        }else if(res.status == 13){
                            $('#identity-error').css('display','inline-block').html('该身份已注册')
                        }else{
                            console.log(res)
                        }
                    },
                    error:function(err){
                        console.log(err) 
                    }
                })
            }
    })
})





_address = {


    addNewAddress(){

        let pro = $('#pro  option').filter(':selected').attr('name');
        let city = $('#city  option').filter(':selected').attr('name');
        let con = $('#con  option').filter(':selected').attr('name');
        let detail = $('#detail-address').val();
        if (detail == ''){
            window.wxc.xcConfirm('请填写详细地址','info');
        }else {

            let str= pro + city + con + detail;
            $.ajax({
                type:'POST',
                url : _common_util.getServerURL('admin/add_address'),
                dataType: 'json',
                data:{
                    'address': str
                },
                success: function (res) {
                    if (res.status === 3){
                        let error = "尚未登录";
                        window.wxc.xcConfirm(error,'info');
                    }else if (res.status === 0){
                        console.log(res.data.addressList);
                        window.wxc.xcConfirm('新增地址成功','info',{onOk:function () {

                                $.ajax({
                                    type: 'GET',
                                    url: _common_util.getServerURL('admin/get_account'),
                                    success:function (res) {
                                        if (res.status === 0){
                                            let name = res.data.username;
                                            console.log(res);
                                            $('.address-list').html('');
                                            $.each(res.data.addressList,function (i,item) {
                                                console.log(item);
                                                str= '                          <div class="address-item" >\n' +
                                                    '                                        <div>\n' +
                                                    '                                            <span>'+name+'</span>\n' +
                                                    '                                            <span>'+res.data.phoneNumber+'</span>\n' +
                                                    '                                        </div>\n' +
                                                    '                                        <div>\n' +
                                                    '                                            <span class="saved-address">'+item+'</span>\n' +
                                                    '                                        </div>\n' +
                                                    '                                        <div>\n' +
                                                    '                                            <a class="btn-info" style="display: inline-block" >编辑</a>\n' +
                                                    '                                            <a class="btn-info" style="display: inline-block">删除</a>\n' +
                                                    '                                        </div>\n' +
                                                    '\n' +
                                                    '                                    </div>';

                                                $('.address-list').append(str);
                                            })
                                        }
                                    }
                                })

                            }});

                        //todo 刷新地址列表
                    }
                }
            })


        }

    }


}


